function OAPanel_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="content" class="content" style="margin-top: 0px;">');
	buffer.append('<div class="smalltitle">全部应用 (长按可以加入到常用哦，试试吧)</div>');
	buffer.append('<div class="often border-top-bottom allapp">');
	if(User.OA_Menu.indexOf(",1,")>-1 && User.RolePower.indexOf(",1,")>-1) buffer.append('<div id="often1" val="1" class="line" tablename="分享" tablechar="Share" ids="" rids="" pids="" dids="" tableid="1"><div class="icon"><img src="img/share.png"/></div><div class="name">分享</div></div>');
	if(User.OA_Menu.indexOf(",2,")>-1 && User.RolePower.indexOf(",2,")>-1) buffer.append('<div id="often2" val="2" class="line" tablename="日志" tablechar="Daily" ids="" rids="" pids="" dids="" tableid="2"><div class="icon"><img src="img/daily.png"/></div><div class="name">日志</div></div>');
	if(User.OA_Menu.indexOf(",3,")>-1 && User.RolePower.indexOf(",3,")>-1) buffer.append('<div id="often3" val="3" class="line" tablename="任务" tablechar="Task" ids="" rids="" pids="" dids="" tableid="3"><div class="icon"><img src="img/task.png"/></div><div class="name">任务</div></div>');
	if(User.OA_Menu.indexOf(",4,")>-1 && User.RolePower.indexOf(",4,")>-1) buffer.append('<div id="often4" val="4" class="line" tablename="审批" tablechar="Examine" ids="" rids="" pids="" dids="" tableid="4"><div class="icon"><img src="img/examine.png"/></div><div class="name">审批</div></div>');
	if(User.OA_Menu.indexOf(",37,")>-1 && User.RolePower.indexOf(",37,")>-1) buffer.append('<div id="often37" val="37" class="line" tablename="日程" tablechar="Schedule" ids="" rids="" pids="" dids="" tableid="37"><div class="icon"><img src="img/schedule.png"/></div><div class="name">日程</div></div>');
	if(User.OA_Menu.indexOf(",25,")>-1 && User.RolePower.indexOf(",25,")>-1) buffer.append('<div id="often25" val="25" class="line" tablename="打卡记录" ids="" rids="" pids="" tableid="25"><div class="icon"><img src="img/checkin2.png"/></div><div class="name">打卡记录</div></div>'); 
	if(User.OA_Menu.indexOf(",7,")>-1 && User.RolePower.indexOf(",7,")>-1)  buffer.append('<div val="7" class="line" tablename="打卡设置"><div class="icon"><img src="img/checkset.png"/></div><div class="name">打卡设置</div></div>');
	if(User.OA_Menu.indexOf(",36,")>-1 && User.RolePower.indexOf(",36,")>-1)  buffer.append('<div val="36" class="line" tablename="外勤签到"><div class="icon"><img src="img/waiqin.png"/></div><div class="name">外勤签到</div></div>');
	if(User.OA_Menu.indexOf(",27,")>-1 && User.RolePower.indexOf(",27,")>-1) buffer.append('<div val="27" class="line" tablename="打卡报表"><div class="icon"><img src="img/checkreport.png"/></div><div class="name">打卡报表</div></div>');
	if(User.OA_Menu.indexOf(",21,")>-1 && User.RolePower.indexOf(",21,")>-1) buffer.append('<div val="21" class="line" tablename="记事本"><div class="icon"><img src="img/notebook.png"/></div><div class="name">记事本</div></div>');
	buffer.append('<div class="line" tablename="添加应用"><div class="icon"><img src="img/addapp.png"/></div><div class="name">添加应用</div></div>');
	buffer.append('</div>');
	buffer.append('<div class="crmreport" >');
		buffer.append('<div class="monthreport">');
			buffer.append('<div class="titles"><div class="icon"><img src="img/monthreport.png"/></div><div class="name">本月工作汇总</div></div>');
			buffer.append('<div class="list" val="1" tablename="分享" tablechar="Share" ids="" rids="" pids="" dids="" tableid="1">');
				buffer.append('<div class="left"><img src="img/share3.png"/></div>');
				buffer.append('<div class="right"><div class="num"><font id="sharecount">0</font>个</div><div class="name">发出的分享</div></div>');
			buffer.append('</div>');
			buffer.append('<div class="list" val="2" tablename="日志" tablechar="Daily" ids="" rids="" pids=""  dids="" tableid="2">');
				buffer.append('<div class="left"><img src="img/daily3.png"/></div>');
				buffer.append('<div class="right"><div class="num"><font id="dailycount">0</font>个</div><div class="name">发出的日志</div></div>');
			buffer.append('</div>');
			buffer.append('<div class="list" val="3" tablename="任务" tablechar="Task" ids="" rids="" pids=""  dids="" tableid="3">');
				buffer.append('<div class="left"><img src="img/task3.png"/></div>');
				buffer.append('<div class="right"><div class="num"><font id="taskcount">0</font>个</div><div class="name">执行的任务</div></div>');
			buffer.append('</div>');
			buffer.append('<div class="list" val="4" tablename="审批" tablechar="Examine" ids="" rids="" pids=""  dids="" tableid="4">');
				buffer.append('<div class="left"><img src="img/examine3.png"/></div>');
				buffer.append('<div class="right"><div class="num"><font id="examinecount">0</font>个</div><div class="name">发出的审批</div></div>');
			buffer.append('</div>');
			buffer.append('<div class="list" val="5">');
				buffer.append('<div class="left"><img src="img/notepad3.png"/></div>');
				buffer.append('<div class="right"><div class="num"><font id="notepadcount">0</font>个</div><div class="name">记事数量</div></div>');
			buffer.append('</div>');
			buffer.append('<div class="list" val="6">');
				buffer.append('<div class="left"><img src="img/sign3.png"/></div>');
				buffer.append('<div class="right"><div class="num"><font id="signcount">0</font>个</div><div class="name">出勤天数</div></div>');
			buffer.append('</div>');
		buffer.append('</div>');
	buffer.append('</div>');

	buffer.append('</div>');
	return buffer.toString();
};

function FindOAReport(){
	if($(".allapp").length==0)
	{
		return;
	}
	var data = {};
		data.act = "Find_OA_Report";
		data.userid = userid;
		data.comid = comid;
		data.source = source;  
		data.version = version;
		data.sign=GetSign(data.act);
		mui.getJSON(index_domain, data, function(json) {
		if (json.state) {
		   $("#sharecount").html(json.data.sharecount);
		   $("#dailycount").html(json.data.dailycount);
		   $("#taskcount").html(json.data.taskcount);
		   $("#examinecount").html(json.data.examinecount);
		   $("#notepadcount").html(json.data.notepadcount);
		   $("#signcount").html(json.data.signcount);
		} else {
		}
	});
	mui(".monthreport").on("tap",".list",function(){
		var index=$(this).attr("val");
		var info=$(this);
		var tablename=info.attr("tablename");
		var tableid=info.attr("tableid");
		var tablechar=info.attr("tablechar");
		var date=new Date();
		var year=date.getFullYear();
		var month=date.getMonth()+1;
		var begindate=year+"-"+month+"-01 00:00:00";
		var enddate=year+"-"+month+"-"+DayNumOfMonth(year,month)+" 23:59:59";
		if(index<=4)
		{
			var title="本月发出的"+tablename;
			var inout="out";
			if(index==3){title="本月执行的"+tablename; inout="exe";}
			myScroll1 = OpenScroll(1,title,"",function(pageindex){
										Receive_Data(info,pageindex,inout,begindate,enddate);
								},function(){

								});
								Receive_Data(info,1,inout,begindate,enddate);
								eval("Init_"+tablechar+"();");
		}else if(index==5)
		{
			myScroll1 = OpenScroll(1,"本月记事数量","",function(pageindex){
										Receive_NotePad(pageindex,begindate,enddate);
								},function(){
									
								});
								Receive_NotePad(1,begindate,enddate);
								$("#divmsg1").css("background","#faf8ed");
		}else if(index==6)
		{
			OpenWindow(2,"本月出勤天数","<div class='rili'><img src='img/rili.png' width='20'/></div>",function(){
									if($("#divmsg100").length>0)
									{
										CloseMeng2();
										return;
									}
									$("#divmsg2 .title").css("z-index","101");
									Show_Month(function(year,month){
										$("#contentlist2").html('<div id="loading2" class="loading"><img src="img/loading.gif"/></div>');
										Receive_SignWork(userid,1,year,month);
									});
								});
								Receive_SignWork(userid,1);
		}
	});
};

function Set_Often_Menu(classname){
	mui(classname).off("longtap",".line");
	mui(classname).on("longtap",".line",function(){
		var ids = CRM.ListVal($("#oftenapp .line"));
		var data={};
		var tips="";
		data.act = "Set_Often_Menu";
		data.userid=userid;
		data.comid=comid;
		data.source=source;
		data.itemid=$(this).attr("val");
		data.sign=GetSign(data.act);
		if(classname==".oftenapp"){
		    data.state="delete";
		    ids=(","+ids+",").replace(","+data.itemid+",",",");
		    tips="您确定要把该应用从常用中删除吗？";
		}else{
		    data.state="add";
		    ids=(","+ids+","+data.itemid+",");
		    tips="您确定要把该应用加入到常用中吗？";
		}
		plus.nativeUI.confirm(tips, function(event){
			if(event.index==1)
			{
			
			mui.getJSON(index_domain, data, function(json) {
				plus.nativeUI.toast(json.msg);
				
				User.Often_Menu = ids;
				plus.storage.setItem("crm_user",JSON.stringify(User));
				$("#iframe").html(Apply_Code());
		      	$(".footer .name").css("color","#8f8f94");
		      	$("#nav_app .name").css("color","#1795cf");
		      	Init_OAPanel(".oftenapp");
		      	Init_CRMPanel(".oftenapp");
		      	Init_HRPanel(".oftenapp");
		      	get("oa_panel").addEventListener("tap",function(){
		      		OpenWindow3(0,"办公OA","",null);
					$("#contentlist0").html(OAPanel_Code());
					Init_OAPanel(".allapp");
		      	});
		      	get("crm_panel").addEventListener("tap",function(){
		      		OpenWindow3(0,"销售CRM","",null);
					$("#contentlist0").html(CRMPanel_Code());
					Init_CRMPanel(".allapp");
		      	});
		      	get("hr_panel").addEventListener("tap",function(){
		      		OpenWindow3(0,"人力资源HR","",null);
					$("#contentlist0").html(HRPanel_Code());
					Init_HRPanel(".allapp");
		      	});
			});
			}
			},"提示", ["取消","确认"]);
		});
};

function Init_OAPanel(classname)
{
	if(classname==".allapp"){
		FindOAReport();
	}
	$("#contentlist0").css("background","#ececec");
	Set_Often_Menu(classname);
	mui(classname).on("tap",".line",function(){
		var tablename=$(this).attr("tablename");
		var tableid=$(this).attr("tableid");
		var tablechar=$(this).attr("tablechar");
		var info=$(this);
	      					if(tablename=="分享" || tablename=="日志" || tablename=="任务" || tablename=="审批" || tablename=="公告" || tablename=="日程")
							{
		      					myScroll1 = OpenScroll(1,tablename+"列表<font style='font-size:12px;'> ▼</font>","<font>+</font>",function(pageindex){
										Receive_Data(info,pageindex);
								},function(){
									touserid="";todepartid="";tocomid="";
									OpenWindow(2,tablename,"保存",function(){
										Publish_Submit(tableid);
									});
									setTimeout(function(){
									$("#contentlist2").html(Publish_Data(tableid));
									Init_Publish(tableid);
									},10);
								});
								Receive_Data(info,1);
								eval("Init_"+tablechar+"();");
							}else if(tablename=="打卡记录")
							{
								OpenWindow(2,tablename+"列表","<div class='rili'><img src='img/rili.png' width='20'/></div>",function(){
									if($("#divmsg100").length>0)
									{
										CloseMeng2();
										return;
									}
									$("#divmsg2 .title").css("z-index","101");
									Show_Month(function(year,month){
										$("#contentlist2").html('<div id="loading2" class="loading"><img src="img/loading.gif"/></div>');
										Receive_SignReport(userid,1,year,month);
									});
								});
								Receive_SignReport(userid,1);
							}
							else if(tablename=="记事本")
							{
								myScroll1 = OpenScroll(1,tablename+"列表<font style='font-size:12px;'> ▼</font>","<font>+</font>",function(pageindex){
										Receive_NotePad(pageindex);
								},function(){
									Open_Detail(0,"");
								});
								Receive_NotePad(1);
								Init_NotePads();
								$("#divmsg1").css("background","#faf8ed");
							}
							else if(tablename=="打卡设置")
							{
								OpenWindow(1,tablename+"列表","<font>+</font>",function(){
									OpenWindow(2,"新增打卡规则","保存",function(){
										Save_SignRule();
									});
									setTimeout(function(){
									$("#contentlist2").html(SignRuleAdd_Code(0,0,"",0));
									Init_SignRuleAdd();
									},10);
								});
								Receive_SignRule(1);
								
							}else if(tablename=="打卡报表")
							{
								myScroll1 = OpenScroll(1,"打卡报表","<div class='rili'><img src='img/rili.png' width='20'/></div>",function(pageindex){
									Receive_SignStastics(pageindex,years,months);
								},function(){
									if($("#divmsg100").length>0)
									{
										CloseMeng2();
										return;
									}
									$("#divmsg1 .title").css("z-index","101");
									Show_Month(function(year,month){
										$("#divmsg1").attr("pageindex","0");
										pageindex=1;
										$("#contentlist1").html("");
										$("#loading1").html('<img src="img/loading.gif"/>');
										myScroll1.refresh();
										Receive_SignStastics(1,year,month);
									});
								},SignStastics_Code(),70);
								Receive_SignStastics(1);
							}else if(tablename=="外勤签到")
							{
								OpenWindow(2,"外勤签到","保存",function(){
										Save_Sign();
								});
								GetNewPos(function(e){
									$("#contentlist2").html(SignAdd_Code(e.address,e.latitude,e.longitude));
									Init_SignAdd();
								});
								
							}else if(tablename=="添加应用")
							{
								OpenWindow2(2,"添加应用","",function(){
								});
								$("#contentlist2").html("");
								addoa.removeClass("hidden");
								
								$("#contentlist2").append(addoa);
							}
							
	});
};